<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="strutsTags"%>
<%@ taglib prefix="ty" uri="/wyzzTags"%>
<script type="text/javascript" src="dwr/interface/searchEmp.js"></script>

<script language="javascript">
	//通过 topSearchKey 里面的内容，搜索匹配的no或者name，生成下来列表供用户选择
	function topFindEmpNoOrName(){
		var ele=model.simple.getElement("topSearchKey");
		var searchValue=ele.value.trim();
		ele.value=searchValue;
		searchEmp.searchNoOrName(searchValue,callback);
		function callback(idNos){
			model.simple.setSelectDiv("topSearchKey","divTopSearchSelect",idNos);
		}
	}

	//跳转到empTreeInit.action，根据topSearchKey里面的内容来显示对应的员工信息
	function topSearchEmp() {
		var searchKey=model.simple.getElementValue("topSearchKey");
		if(hrm.common.isEmpty(searchKey)){
			alert("请输入您要搜索的员工信息！");
			return;
		}
		window.location.href = encodeURI("profile/empTreeInit.action?id=" + encodeURIComponent(searchKey)); 
	}

	/**
	* 在菜单数组(menuList)里面增加一个菜单，其属性包括menuUrl,menuDesc,menuIcon, simpleDesc
	*/
	function addOneMenu(menuList,menuUrl,menuDesc/*, menuIcon, simpleDesc*/){
		var menu={};
		menu["url"]=menuUrl;
		menu["desc"]=menuDesc;
		if(arguments[3]!=null && arguments[3]!=""){
			menu["icon"]=hrm.common._imgPath+arguments[3];
		}
		if(arguments[4]==null || arguments[4]==""){
			menu["descSim"]=menuDesc;
		}else{
			menu["descSim"]=arguments[4];
		}
		menuList[menuList.length]=menu;
	}
	/**
	* 在菜单数组(menuList)里面增加一个菜单，其属性包括menuDesc,dir,subMenu, menuUrl, menuIcon。
	* 如果增加菜单里面没有子菜单(subMenu)，则不增加这个菜单
	*/
	function addOneMenuWithSubMenu(menuList,menuDesc,dir,subMenu/*, menuUrl, menuIcon*/){
		if(subMenu.length<1){
			return;
		}
		var menu={};
		menu["desc"]=menuDesc;
		menu["dir"]=dir;
		for(var i=0;i<subMenu.length;i++){
			if(subMenu[i]["url"].indexOf("")==-1){
				subMenu[i]["url"]=""+dir+"/"+subMenu[i]["url"];
			}
		}
		menu["subMenu"]=subMenu;
		if(arguments[4]==null || arguments[4]==""){
			menu["url"]=subMenu[0]["url"];
		}else{
			menu["url"]=arguments[4];
		}
		if(arguments[5]!=null && arguments[5].length){
			menu["icon"]=hrm.common._imgPath+arguments[5];
		}
		menuList[menuList.length]=menu;
	}
	/**
	* 初始化一级、二级菜单数组，每个菜单是一个object，包含属性：desc(描述)，dir(隶属目录)，url，subMenu(子菜单数组)，icon(图标),descSim(简单描述)
	*/
	function getHrmAllMenu(){
		var menuList=new Array();
		var indexTmp=0;
		//首页
		var subMenuList=new Array();
		<ty:auth auths="111">addOneMenu(subMenuList,"profile/myInfo.action?empNo=<s:property value='#session.userinfo.id'/>&empName=<s:property value='#session.empName'/>","我的资料");</ty:auth>
		<ty:auth auths="411">addOneMenu(subMenuList,"examin/empExaminAdd.action?tab=1","休假申请");</ty:auth>
		<ty:auth auths="411">addOneMenu(subMenuList,"examin/empExaminAdd.action?tab=2","加班申请");</ty:auth>
		addOneMenuWithSubMenu(menuList,"首页","homepage",subMenuList,"homepage/index.action");

		//员工
		subMenuList=new Array();
		<ty:auth auths="101 or 111,3 or 111,2">addOneMenu(subMenuList,"profile/searchEmp.action","员工管理","users.gif");</ty:auth>
		<ty:auth auths="101">addOneMenu(subMenuList,"profile/empCreateInit.action","新员工入职","users.gif","新增员工");</ty:auth>
		<ty:auth auths="101">addOneMenu(subMenuList,"profile/empQuitManagement.action","离职员工管理","users.gif","离职员工");</ty:auth>
		<ty:auth auths="101">addOneMenu(subMenuList,"profile/manageContract.action","合同管理","Tasks.gif");</ty:auth>
		<ty:auth auths="101 or 111,3 or 111,2">addOneMenu(subMenuList,"profile/profileManagement.action","档案管理","Tasks.gif");</ty:auth>
		<ty:auth auths="101 or 111">addOneMenu(subMenuList,"profile/empTreeInit.action?id=<s:property value='#session.userinfo.id'/>","员工通讯录","namelist.gif","通讯录");</ty:auth>
		<ty:auth auths="111">addOneMenu(subMenuList,"profile/myInfo.action?tab=1&empNo=<s:property value='#session.userinfo.id'/>&empName=<s:property value='#session.empName'/>","我的资料","member_face2.gif");</ty:auth>
		<ty:auth auths="101,3 or 101,2">addOneMenu(subMenuList,"profile/empReport.action","员工报表","MeetingReports.gif","报表");</ty:auth>
		<ty:auth auths="101,3">addOneMenu(subMenuList,"profile/orgDeptManage.action","部门管理","Teams.gif");</ty:auth>
		<ty:auth auths="101,3">addOneMenu(subMenuList,"profile/showPbManagePage.action","职位管理","Teams.gif");</ty:auth>
		<ty:auth auths="101,3">addOneMenu(subMenuList,"profile/showPositionStructure.action","组织结构管理","Teams.gif");</ty:auth>
		<ty:auth auths="101,3">addOneMenu(subMenuList,"profile/showOrgMap.action","组织结构图","org_chart.png");</ty:auth>
		addOneMenuWithSubMenu(menuList,"员工","profile",subMenuList,null,"icon1.gif");
		
		//薪资
		subMenuList=new Array();
		<ty:auth auths="201">addOneMenu(subMenuList,"compensation/searchSalary.action?emp.empStatus=1","员工薪资配置","Newsletters.gif","薪资配置");</ty:auth>
		<ty:auth auths="201 or 211,3 or 211,2">addOneMenu(subMenuList,"compensation/searchSalaryPaid.action","每月薪资发放","ProjectPaste.gif","薪资发放");</ty:auth>
		<ty:auth auths="201 or 211">addOneMenu(subMenuList,"compensation/mySalaryPaid.action","薪资发放历史","ProjectPaste.gif");</ty:auth>
		<ty:auth auths="201">addOneMenu(subMenuList,"compensation/searchEmpbenefit.action?employee.empStatus=1","员工社保管理","Documents.gif","社保");</ty:auth>
		<ty:auth auths="201">addOneMenu(subMenuList,"compensation/searchEbp.action","员工社保补缴","Documents.gif","社保补缴");</ty:auth>
		<ty:auth auths="201">addOneMenu(subMenuList,"compensation/searchBeneHistory.action","社保缴费历史","Documents.gif","缴费历史");</ty:auth>
		<ty:auth auths="201,3 or 201,2">addOneMenu(subMenuList,"compensation/searchBatchCompaplan.action","员工调薪计划","SalaryPaidApprove.gif","调薪计划");</ty:auth>
		<ty:auth auths="201,3 or 201,2">addOneMenu(subMenuList,"compensation/searchCompaplan.action","调薪历史查询","SalaryPaidApprove.gif","调薪历史");</ty:auth>
		<ty:auth auths="201,3">addOneMenu(subMenuList,"compensation/salaryRpInit.action","薪资报表","CompaReport.gif","报表");</ty:auth>
		<ty:auth auths="201,3 or 201,2">addOneMenu(subMenuList,"compensation/compensationConfig.action","薪资设置","Releases.gif");</ty:auth>
		<ty:auth auths="201,3 or 201,2">addOneMenu(subMenuList,"compensation/searchesa.action","薪资帐套配置","Releases.gif");</ty:auth>
		addOneMenuWithSubMenu(menuList,"薪资","compensation",subMenuList,null,"icon2.gif");

		//考勤
		subMenuList=new Array();
		<ty:auth auths="411">addOneMenu(subMenuList,"examin/myExamins.action","我的请假加班","MyProject.gif");</ty:auth>
		<ty:auth auths="401 or 411">addOneMenu(subMenuList,"examin/empExaminAdd.action","请假加班申请","CreateProject.gif","申请");</ty:auth>
		<ty:auth auths="411,3 or 411,2">addOneMenu(subMenuList,"examin/deptExaminSearch.action","经理审批","DeptApprove.gif");</ty:auth>
		<ty:auth auths="401,3 or 401,2">addOneMenu(subMenuList,"examin/hrExaminSearch.action","HR备案","DeptApprove.gif");</ty:auth>
		<ty:auth auths="401 or 411,3 or 411,2">addOneMenu(subMenuList,"examin/allExaminSearch.action","请假加班列表","Reports.gif","请假加班");</ty:auth>
		<s:if test="@com.wyzz.hr.base.ComonBeans@getShiftEnable()==1">
		<ty:auth auths="401 or 411,3 or 411,2">addOneMenu(subMenuList,"examin/examinScheduleSearch.action","排班管理","TimePeriods.gif","排班");</ty:auth>
		<ty:auth auths="401 or 411,3 or 411,2">addOneMenu(subMenuList,"examin/originalDataImportShow.action","刷卡管理","TimePeriods.gif","刷卡");</ty:auth>
		<ty:auth auths="(401,3 or 401,2) and 421">addOneMenu(subMenuList,"examin/attdSyncRecordShow.action","考勤机用户同步","TimePeriods.gif","同步");</ty:auth>
		</s:if>
		<ty:auth auths="401 or 411">addOneMenu(subMenuList,"examin/searchAttenddaily.action","每日考勤记录","Calendar.gif","每日考勤");</ty:auth>
		<ty:auth auths="401 or 411,3 or 411,2">addOneMenu(subMenuList,"examin/searchAttendmonthly.action","每月考勤汇总 ","Calendar.gif","每月汇总");</ty:auth>
		<ty:auth auths="401 or 411">addOneMenu(subMenuList,"examin/searchMyAttendmonthly.action","每月考勤历史","Calendar.gif","每月考勤历史");</ty:auth>
		<ty:auth auths="401,3 or 401,2">addOneMenu(subMenuList,"examin/examinReport.action","考勤报表 ","AttdReports.gif","报表");</ty:auth>
		<ty:auth auths="401,3 or 401,2">addOneMenu(subMenuList,"examin/examinWfConfig.action","审批设置","Releases.gif");</ty:auth>
		<ty:auth auths="401,3 or 401,2">addOneMenu(subMenuList,"examin/leavebalanceManage.action","考勤设置","Releases.gif");</ty:auth>
		addOneMenuWithSubMenu(menuList,"考勤","examin",subMenuList,null,"icon3.gif");
		//系统
		subMenuList=new Array();
		<ty:auth auths="911">addOneMenu(subMenuList,"configuration/userList.action","用户管理","CreateUsers.gif","用户");</ty:auth>
		<ty:auth auths="921">addOneMenu(subMenuList,"configuration/getRoleList.action","角色管理","CreateRoles.gif","角色");</ty:auth>
		<ty:auth auths="952">addOneMenu(subMenuList,"configuration/config.action","基础表格设置","Rebuild.gif","基础表格");</ty:auth>
		 addOneMenuWithSubMenu(menuList,"系统","configuration",subMenuList,null,"icon6.gif");
		return menuList;
	}	

	//通过当前url得到菜单列表的对应索引
	function getCurrTopMenuIndex(menuList){
		for(var i=0;i<menuList.length;i++){
			if(document.location.pathname.indexOf("/"+menuList[i]["dir"]+"/")>-1){
				return i;
			}
		}
		return -1;
	}
	//初始化页面顶部菜单html
	function initTopMenu(menuList,selectIndex){
		var menuArr=new Array();
		for(var i=0;i<menuList.length;i++){
			var j=menuList.length-1-i;
			if(i==selectIndex){
				menuArr[j]='<li class="sswo">'
			}else{
				menuArr[j]='<li class="ss">'
			}
			menuArr[j]+='<a href="'+menuList[i]["url"]+'" onmouseover="showSubMenu(this,'+i+');" >'+menuList[i]["desc"]+'</a>';
		}
		var divEle=model.simple.getElement("topmenu");
		divEle.innerHTML="<ul>"+menuArr.join("\n")+"</ul>";
	}
	//根据选中的一级菜单，先是对应的二级菜单
	function showSubMenu(menuEle,selectIndex){
		//根据cookie判断是否显示二级菜单
		if(hrm.common.getCookie('showLeftCol')=="true"){
			return;
		}
		//得到二级菜单
		var subMenuArr=hrmAllMenu[selectIndex]["subMenu"];
		//设定二级菜单html
		var menuArr=new Array();
		for(var i=0;i<subMenuArr.length;i++){
			menuArr[i]='<a href="'+subMenuArr[i]["url"]+'">'+subMenuArr[i]["descSim"]+'</a>';
		}
		//将二级菜单内容写入div
		var divEle=model.simple.getElement("submenu");
		divEle.style.width="";
		divEle.innerHTML="<table id='subMenuTable' align='left'><tr><td style='white-space:nowrap'>"+menuArr.join("</td><td>")+"</td></tr></table>";
		//设定二级菜单位置
		var tableEle=model.simple.getElement("subMenuTable");
		//为超连接字体变粗时预留位置
		tableWidth=tableEle.offsetWidth+10;
		tableEle.style.width=tableWidth+"px";
		divEle.style.width=tableWidth+"px";
		var menuPosition=model.simple.getElementPosition(menuEle);
		var divPosition=model.simple.getElementPosition(divEle);
		if(divPosition.left>menuPosition.left){
			var width=divPosition.left-menuPosition.left+divEle.offsetWidth;
			divEle.style.width=width+"px";
		}
	}	
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
	class="top">
	<tr style="padding-left: 5px; padding-top: 5px; padding-bottom: 5px">
		<td rowspan="2" width="200">
			<img src="resource/images/logo.gif" alt="logo" />
		</td>
		<td align="right" valign="bottom">
			
			&nbsp;
			<div
				style="position: absolute; z-index: 10; border: black 1px solid; bgColor: FFFFFF; display: none;"
				id="divTopSearchSelect"></div>
		</td>
	</tr>

	<tr>
		<td height="25" align="right" valign="bottom">
			<div id="topmenu"></div>
		</td>
	</tr>

	<tr class="visits">
		<td nowrap="nowrap">
			欢迎您，
			<s:property value="#session['empName']" />
			|
			<a href="configuration/logout.action"><span class="visitsA">退出系统</span>
			</a>
		</td>
		<td align="right">
			<div id="submenu" style="z-index: 10" class="secondmenu"></div>
		</td>
	</tr>
</table>
<script language="javascript">
//初始化一级二级菜单
var hrmAllMenu=getHrmAllMenu();
//初始化当前菜单索引
var currMenuIndex=getCurrTopMenuIndex(hrmAllMenu);
initTopMenu(hrmAllMenu,currMenuIndex);
</script>
<!-- end top -->
